/**
 * 高德地图
 * @author 木人心
 * @version 1.0.0
 */
import { AMapResolve, InitAMapOption } from '@utils/amap/type'
import AMapLoader from '@amap/amap-jsapi-loader'
import { aMapSettings } from '@utils/amap/config'
/**
 * 初始化地图
 * @param option
 */
export function initAMap (option: InitAMapOption) {
  return new Promise<AMapResolve>((resolve, reject) => {
    AMapLoader.load({
      ...aMapSettings.loadOptions,
      plugins: option.plugins || []
    }).then((_AMap: typeof AMap) => {
      const map: AMap.Map = new _AMap.Map(option.el, {
        mapStyle: option.mapStyle || aMapSettings?.mapStyle,
        ...option.mapOption || {}
      })
      resolve({ AMap: _AMap, map })
    }).catch(reject)
  })
}
